<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of welcome
 *
 * @author Obi
 */
class Admin_news extends MY_Controller {

    function __construct() {
        parent::__construct();

        $cek_admin = $this->session->userdata('cek_admin');
        if (!$cek_admin)
            redirect("admin");

        $this->mnews = new M_news();
    }

    function index() {

        $data['title'] = 'Data Konten News';

        $data['list'] = $this->mnews->get();

        $data['isi'] = 'isi';
        $this->load->view('template_admin', $data);
    }

    function tambah() {

        $data['title'] = 'Tambah Berita';

        $data['newsid'] = "";
        $data['title'] = "";
        $data['news'] = "";
        $data['status'] = "1";

        $data['isi'] = 'form';
        $this->load->view('template_admin', $data);
    }

    function edit($id = NULL) {

        $data['title'] = 'Ubah Berita';

        $dt = $this->mnews->where("newsid = '$id'")->get();

        $data['newsid'] = $dt->newsid;
        $data['title'] = $dt->title;
        $data['news'] = $dt->news;
        $data['status'] = $dt->status;


        $data['isi'] = 'form';
        $this->load->view('template_admin', $data);
    }

    function delete($id) {
        $this->mnews->delete($id);
        redirect("admin_news");
    }

    function simpan() {
        $id = $this->input->post('newsid');

        $data = array(
            'title' => $this->input->post('title'),
            'news' => $this->input->post('news'),
            'status' => $this->input->post('status'),
            'datekeyin' => date('Y-m-d H:i:s')
        );

        if ($id == "") {
            $this->mnews->insert($data);
        } else {
            $this->mnews->update($data, $id);
        }

        redirect("admin_news");
    }

}

?>
